package com.gery.tn.ui.search;

import com.gery.tn.ui.MainWindow;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;



public class ResultListItem extends JPanel {

    private JLabel nameLabel;
    private JLabel telLabel;
    private JLabel pointLabel;
    private ImageIcon img;
    private long id;
    private MainWindow myParent;
    
    
    
    public ResultListItem(int top, MainWindow parent) {
        this.setLayout(null);
        this.setBorder(null);
        this.setBounds(0, top, 601, 40);
        this.setVisible(false);
        this.myParent = parent;
        img = new ImageIcon(this.getClass().getClassLoader().getResource("com/gery/tn/ui/images/resultImage.png"));
        
        nameLabel = new JLabel("");
        telLabel = new JLabel("");
        pointLabel = new JLabel("");
        
        nameLabel.setBounds(46, 3, 200, 30);
        telLabel.setBounds(319, 2, 150, 30);
        pointLabel.setBounds(554, 2, 150, 30);
        nameLabel.setFont(new Font("Apple", Font.BOLD, 14));
        telLabel.setFont(new Font("Apple", Font.BOLD, 12));
        pointLabel.setFont(new Font("Apple", Font.BOLD, 12));
        nameLabel.setForeground(Color.DARK_GRAY);
        telLabel.setForeground(Color.GRAY);
        pointLabel.setForeground(Color.GRAY);
        
        this.add(nameLabel);
        this.add(telLabel);
        this.add(pointLabel);
        
        this.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                myParent.getAppointmentPanel().panelOn(id, ResultListItem.this.getLabelName());
                myParent.getResultList().clearList();
                myParent.getSearchPanel().clearTextField();
                myParent.getAppointmentPanel().setPickerFocus();
            }
            @Override
            public void mouseEntered(MouseEvent e) {
                nameLabel.setForeground(new Color(114, 166, 254));
                ResultListItem.this.setCursor(new Cursor(Cursor.HAND_CURSOR));
            }
            @Override
            public void mouseExited(MouseEvent e) {
                nameLabel.setForeground(Color.DARK_GRAY);
            }
        });
        
    }    
    
    
    //--- Setters
    public void setResult(long id, String name, String tel, String point) {
        this.id = id;
        nameLabel.setText(name);
        telLabel.setText(tel);
        pointLabel.setText(point);
        this.setVisible(true);
    }
    
    //--- Getters
    public String getLabelName() {
        return nameLabel.getText();
    }
    public long getID() {
        return id;
    }
    
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);      
        g.drawImage(img.getImage(), 0, 0, this.getWidth(), this.getHeight(), this);
    }
    
}
